package com.pan.admin.module.area.controller;

import com.pan.admin.common.annotation.Log;
import com.pan.admin.common.core.controller.BaseController;
import com.pan.admin.common.core.domain.AjaxResult;
import com.pan.admin.common.core.page.TableDataInfo;
import com.pan.admin.common.enums.BusinessType;
import com.pan.admin.common.utils.poi.ExcelUtil;
import com.pan.admin.module.area.entity.LoanProductPlanArea;
import com.pan.admin.module.area.service.LoanProductPlanAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 配置机构计划地区Controller
 *
 * @author ts
 * @date 2023-12-28
 */
@RestController
@RequestMapping("/area/area")
public class LoanProductPlanAreaController extends BaseController {
    @Autowired
    private LoanProductPlanAreaService loanProductPlanAreaService;


    /**
     * 查询配置机构计划地区列表
     */
    @PreAuthorize("@ss.hasPermi('area:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(LoanProductPlanArea loanProductPlanArea) {
        startPage();
        List<LoanProductPlanArea> list = loanProductPlanAreaService.list(loanProductPlanArea);
        return getDataTable(list);
    }

    /**
     * 导出配置机构计划地区列表
     */
    @PreAuthorize("@ss.hasPermi('area:area:export')")
    @Log(title = "配置机构计划地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LoanProductPlanArea loanProductPlanArea) {
        List<LoanProductPlanArea> list = loanProductPlanAreaService.list(loanProductPlanArea);
        ExcelUtil<LoanProductPlanArea> util = new ExcelUtil<LoanProductPlanArea>(LoanProductPlanArea.class);
        util.exportExcel(response, list, "配置机构计划地区数据");
    }

    /**
     * 获取配置机构计划地区详细信息
     */
    @PreAuthorize("@ss.hasPermi('area:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(loanProductPlanAreaService.getById(id));
    }

    /**
     * 新增配置机构计划地区
     */
    @PreAuthorize("@ss.hasPermi('area:area:add')")
    @Log(title = "配置机构计划地区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LoanProductPlanArea loanProductPlanArea) {
        return toAjax(loanProductPlanAreaService.insertLoanProductPlanArea(loanProductPlanArea));
    }

    /**
     * 修改配置机构计划地区
     */
    @PreAuthorize("@ss.hasPermi('area:area:edit')")
    @Log(title = "配置机构计划地区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LoanProductPlanArea loanProductPlanArea) {
        return toAjax(loanProductPlanAreaService.updateLoanProductPlanArea(loanProductPlanArea));
    }

    /**
     * 删除配置机构计划地区
     */
    @PreAuthorize("@ss.hasPermi('area:area:remove')")
    @Log(title = "配置机构计划地区", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(loanProductPlanAreaService.batchDeleteById(ids));
    }


}
